﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vowei.Core.Models;
using System.ComponentModel.DataAnnotations;

namespace Vowei.Data.Models.Statistics
{
    public class WorksStatistics<T>
    {
        public T Item { get; set; }

        [Display(Name = "未完成的工作项目数目")]
        public int ActiveTicketsCount { get; set; }

        [Display(Name = "已完成的工作项目数目")]
        public int ClosedTicketsCount { get; set; }

        [Display(Name = "未完成的任务数目")]
        public int ActiveTasksCount { get; set; }

        [Display(Name = "已完成的任务数目")]
        public int ClosedTasksCount { get; set; }

        [Display(Name = "已完成的工时")]
        public TimeSpan CompletedWorkHours { get; set; }

        [Display(Name = "未完成的工时")]
        public TimeSpan TotalEstimatedDuration { get; set; }

        [Display(Name = "挣值")]
        public float EarnedBusinessValue { get; set; }

        [Display(Name = "总值")]
        public float TotalBusinessValue { get; set; }

        [Display(Name = "未完成的需求数目")]
        public int ActiveRequirementsCount { get; set; }

        [Display(Name = "已完成的需求数目")]
        public int ClosedRequirementsCount { get; set; }
    }

    public class WorksStatistics
    {
        [Display(Name = "未完成的工作项目数目")]
        public int ActiveTicketsCount { get; set; }

        [Display(Name = "已完成的工作项目数目")]
        public int ClosedTicketsCount { get; set; }

        [Display(Name = "未完成的任务数目")]
        public int ActiveTasksCount { get; set; }

        [Display(Name = "已完成的任务数目")]
        public int ClosedTasksCount { get; set; }

        [Display(Name = "已完成的工时")]
        public TimeSpan CompletedWorkHours { get; set; }

        [Display(Name = "未完成的工时")]
        public TimeSpan TotalEstimatedDuration { get; set; }

        [Display(Name = "挣值")]
        public float EarnedBusinessValue { get; set; }

        [Display(Name = "总值")]
        public float TotalBusinessValue { get; set; }

        [Display(Name = "未完成的需求数目")]
        public int ActiveRequirementsCount { get; set; }

        [Display(Name = "已完成的需求数目")]
        public int ClosedRequirementsCount { get; set; }
    }

    public class RequirementStatistics : WorksStatistics
    {
        [Display(Name = "需求")]
        public Requirement Requirement { get; set; }

        [Display(Name = "需求级别")]
        public int Level { get; set; }
    }

    public class EarnedValueStatistics : IComparable<EarnedValueStatistics>, IComparable
    {
        [Display(Name = "日期")]
        public DateTime Date { get; set; }

        [Display(Name = "计划工作量的预算费用")]
        public double BCWS { get; set; }

        [Display(Name = "已完成工作量的实际费用")]
        public double ACWP { get; set; }

        [Display(Name = "已完成工作量的预算成本")]
        public double BCWP { get; set; }

        [Display(Name = "计划工时")]
        public TimeSpan PlanedWorkHours { get; set; }

        [Display(Name = "实际工时")]
        public TimeSpan FinishedWorkHours { get; set; }

        [Display(Name = "费用偏差")]
        public double CV { get { return BCWP - ACWP; } }

        [Display(Name = "进度偏差")]
        public double SV { get { return BCWP - BCWS; } }

        [Display(Name = "费用执行指标")]
        public double CPI
        {
            get
            {
                if (ACWP != 0.0)
                    return BCWP / ACWP;
                else
                    return 0.0;
            }
        }

        [Display(Name = "进度执行指标")]
        public double SPI
        {
            get
            {
                if (BCWS != 0.0)
                    return BCWP / BCWS;
                else
                    return 0.0;
            }
        }

        public int CompareTo(object obj)
        {
            return CompareTo((EarnedValueStatistics)obj);
        }

        public int CompareTo(EarnedValueStatistics other)
        {
            return Date.CompareTo(other.Date);
        }
    }

    public class DateTimeWorkStatistics : WorksStatistics
    {
        public DateTime Date { get; set; }
    }
}
